home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Bad code
- Date: Sun, 31 Mar 96 12:21:15 GMT
- Organization: none
- Message-ID: <828274875snz@genesis.demon.co.uk>
- References: <4jhau8$hrl@hermes.oanet.com> <4jhmhpINNps7@anvil.ugrad.cs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jhmhpINNps7@anvil.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
-
- >In article <4jhau8$hrl@hermes.oanet.com>,
- > <scorpion@portal.connect.ab.ca> wrote:
- >> I need to know why a piece of my C code doesn't work .
- >>it does like:
- >>
- >> Object.Vertices+i.X = (long) .....
- >> Object.Vertices+i.Y = (long).......
- >> Object.Vertices+i.Z=(long) ........
- >>
- >> Vertices is a pointer to a struct with {long X,Y,Z} that
- >>has been typedef'ed. i is an index vatiable that is added to the
- >>pointer to make is point to the next {long X,Y,Z} typedef'ed
- >>struct . When I go to compile , it says "not a struct or union
- >>type".
- >
- >Object.Vertices is NOT a struct or union type, so you can't use the '.'
- >operator to access members in it. It is a pointer to a structure. Therefore you
- >have to dereference the pointer before accessing a member:
- >
- > (*Object.Vertices+i).x = (long) ....
-
- Or rather:
-
- (*(Object.Vertices+i)).X = (long) ....
-
- >This is a bit clumsy, which is why most programmers use the following
- >equivalent notation:
- >
- > (Object.Vertices+i)->X = ...
-
- More commonly this is written as:
-
- Object.Vertices[i].X = ...
-
- >When I parenthesize Vertices+i , I get an "Identified
- >
- >That's because (Vertices+i) is not a member of Object structure. It is a
- >pointer expression.
-
- Not even that. Vertices is just a member name and by itself is not an
- expression at all, and neither is Vertices+i. Vertices can only form part
- of an expression as the right hand operand of . or -> or argument to
- offsetof().
-
- You cannot write Object.(Vertices + i). An identifier is
- >expected after the ``Object.'' to name the member.
-
- Right, here Vertices is the lefthand operand of + so this is not valid.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-